package com.indexingsystem.system.service.impl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.ServiceTypeInfoVo;
import com.indexingsystem.boss.admin.mapper.ScopesMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.Scopes;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.system.service.IScopesService;

@Service
public class ScopesServiceImpl implements IScopesService {

	@Resource
	private ScopesMapper scopesMapper;

	/**
	 * 通过主键删除资源范围.
	 * 
	 * @param socpesId
	 * @return
	 */
	@Override
	public int deleteByPrimaryKey(String scopesId) {
		return scopesMapper.deleteByPrimaryKey(scopesId);
	}
	
	/**
	 * 通过授权code获取授权类型列表.
	 * @param scopesCodeList
	 * @return
	 */
	@Override
	public Set<Integer> queryScopesTypeByCodes(List<String> scopesCodeList){
		Map<String,Object> codesParam = new HashMap<String,Object>();
		codesParam.put("codesParam", scopesCodeList);
		List<Integer> scopesTypeList = scopesMapper.queryScopesTypeByCodes(codesParam);
		Set<Integer> scopesTypeSet = new HashSet<Integer>();
		for (int i = 0; i <= scopesTypeList.size(); i++) {
			scopesTypeSet.add(scopesTypeList.get(i));
		}
		return scopesTypeSet;
	}
	
	/**
	 * 新增资源范围.
	 * 
	 * @param record
	 * @return
	 */
	@Override
	public int insertSelective(Scopes record) {
		return scopesMapper.insertSelective(record);
	}

	/**
	 * 分页查询资源范围.
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@Override
	public PagedResult<Scopes> selectScopesList(String queryCriteria,Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(scopesMapper.selectScopesList(queryCriteria));
	}

	/**
	 * 通过资源范围id查询资源范围信息.
	 * 
	 * @param socpesId
	 * @return
	 */
	@Override
	public Scopes selectByPrimaryKey(String scopesId) {
		return scopesMapper.selectByPrimaryKey(scopesId);
	}

	/**
	 * 修改资源范围.
	 * 
	 * @param record
	 * @return
	 */
	@Override
	public int updateByPrimaryKeySelective(Scopes record) {
		return scopesMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 获取授权资源范围总数量.
	 * 
	 * @return
	 */
	@Override
	public Integer getScopersCount(String queryCriteria) {
		return scopesMapper.getScopersCount(queryCriteria);
	}

	/**
	 * 通过资源范围code、名称、url查询是否已存在
	 * 
	 * @param record
	 * @return
	 */
	@Override
	public Scopes selectScopesExits(Scopes record) {
		return scopesMapper.selectScopesExits(record);
	}

	/**
	 * 通过资源范围code查询资源范围信息.
	 * 
	 * @param code
	 * @return
	 */
	@Override
	public Scopes selectScopesByCode(String code) {
		return scopesMapper.selectScopesByCode(code);
	}

	/**
	 * 获取授权范围code列表
	 * 
	 * @return
	 */
	@Override
	public List<String> getScopersCodeList() {
		return scopesMapper.getScopersCodeList();
	}
	
	/**
	 * 应用管理获取授权范围code及name列表.
	 * @return
	 */
	@Override
	public List<ServiceTypeInfoVo> getScopersTypeList(){
		return scopesMapper.getScopersTypeList();
	}

	/**
	 * 批量删除资源范围.
	 * 
	 * @param scopesIdList
	 * @return
	 */
	@Override
	public Integer deleteScopesByIdBatch(List<String> scopesIdList) {
		return scopesMapper.deleteScopesByIdBatch(scopesIdList);
	}

	@Override
	public List<Scopes> getScopersURI() {
		// TODO Auto-generated method stub
		return scopesMapper.getScopersURI();
	}
}